<script setup>
import { ref, onMounted } from 'vue'
import { Delete, Check, Picture } from '@element-plus/icons-vue'

//导入接口
import getWaitAuthApi from '@/service/api/check/check'

const getWaitAuthService = getWaitAuthApi.getWaitAuth

const getWaitAuth = async () => {
  try {
    const res = await getWaitAuthService()
    waitForCheckData.value = res.data.map((item) => {
      const date = new Date(parseInt(item.requestTime))

      // 格式化日期字符串
      const year = date.getFullYear()
      const month = ('0' + (date.getMonth() + 1)).slice(-2)
      const day = ('0' + date.getDate()).slice(-2)
      const formattedDate = `${year}-${month}-${day}`
      return {
        requestTime: formattedDate,
        studentNum: item.stuNum,
        requestAuthInfo: item.authInfo,
        prove: item.authImage
      }
    })
  } catch (err) {
    console.log(err)
  }
}
//定义待认证列表
const waitForCheckData = ref([
  // {
  //   requestTime: '2022-07-10',//请求时间
  //   studentNum: 202213407202,//请求学号
  //    requestAuthInfo: '社团活动',//请求身份
  //   prove: []//证明材料
  // }
])
onMounted(() => {
  getWaitAuth()
})

//已检查表数据
const checkedData = ref([
  {
    studentNum: 202213407202,
    identity: '领航前端'
  },
  {
    studentNum: 202213407202,
    identity: '领航前端'
  },
  {
    studentNum: 202213407202,
    identity: '领航前端'
  }
])

//驳回单个
const refuseApplication = (row) => {
  //await artDelChannelsService(row.id) //删除选中行数据
  console.log(row)
  ElMessageBox.confirm('你确定删除该认证？', '提醒：', {
    confirmButtonText: '确定删除',
    cancelButtonText: '取消删除',
    type: 'warning',
    center: true
  })
    .then(() => {
      ElMessage({
        type: 'success',
        message: '删除成功！'
      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '删除失败！'
      })
    })
  //getChannelList() //刷新
}
//认证单个
const acceptApplication = (row) => {
  //await artDelChannelsService(row.id) //删除选中行数据
  console.log(row)
  ElMessageBox.confirm('你确定通过该认证？', '提醒：', {
    confirmButtonText: '确定通过',
    cancelButtonText: '取消通过',
    type: 'warning',
    center: true
  })
    .then(() => {
      ElMessage({
        type: 'success',
        message: '认证成功！'
      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '认证失败！'
      })
    })
  //getChannelList() //刷新
}
//批量操作帖子
//获取未认证的多选
const multipleSelection = ref([])
const handleSelectionChange = (val) => {
  multipleSelection.value = val
}

//批量驳回函数
const refuseSome = () => {
  console.log(multipleSelection.value[0])
  ElMessageBox.confirm('你确定驳回选中的所有认证信息？', '提醒：', {
    confirmButtonText: '确定驳回',
    cancelButtonText: '取消驳回',
    type: 'warning',
    center: true
  })
    .then(() => {
      //发请求
      ElMessage({
        type: 'success',
        message: '驳回成功！'
      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '驳回失败！'
      })
    })
}

//批量通过函数
const acceptSome = () => {
  console.log(multipleSelection.value[0])
  ElMessageBox.confirm('你确定认证通过选中的所有信息？', '提醒：', {
    confirmButtonText: '确定通过',
    cancelButtonText: '取消通过',
    type: 'warning',
    center: true
  })
    .then(() => {
      //发请求
      ElMessage({
        type: 'success',
        message: '认证成功！'
      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '认证失败！'
      })
    })
}

//展示图片区抽屉
const pic = ref(false)
const seeProve = (row) => {
  pic.value = true
  srcList.value = row.prove
}
//证明图片材料
const srcList = ref([
  // 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg',
  // 'https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg',
  // 'https://fuss10.elemecdn.com/0/6f/e35ff375812e6b0020b6b4e8f9583jpeg.jpeg',
  // 'https://fuss10.elemecdn.com/9/bb/e27858e973f5d7d3904835f46abbdjpeg.jpeg',
  // 'https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg',
  // 'https://fuss10.elemecdn.com/3/28/bbf893f792f03a54408b3b7a7ebf0jpeg.jpeg',
  // 'https://fuss10.elemecdn.com/2/11/6535bcfb26e4c79b48ddde44f4b6fjpeg.jpeg'
])
</script>

<template>
  <PageContainer>
    <el-header class="header">
      <div class="header-left">
        <div class="text1"><strong>待认证成员:</strong></div>
        <div class="btn">
          <div class="true">
            <el-button @click="acceptSome" type="success">批量通过身份认证</el-button>
          </div>
          <div class="false">
            <el-button @click="refuseSome" type="danger">批量驳回身份认证</el-button>
          </div>
        </div>
      </div>

      <div class="header-right">
        <div class="text2"><strong>已认证成员:</strong></div>
      </div>
    </el-header>
    <main class="main">
      <div class="layout">
        <!-- 左边表格 -->
        <el-row :gutter="20">
          <el-col :span="14" class="left">
            <div>
              <el-table
                :data="waitForCheckData"
                style="width: 100%"
                :border="true"
                empty-text="暂时没有数据哦~"
                v-loading="loading"
                :height="tableHeight"
                @selection-change="handleSelectionChange"
                stripe
                ref="multipleTable"
              >
                <el-table-column type="selection" width="50" />
                <el-table-column prop="requestTime" label="请求日期" />
                <el-table-column prop="studentNum" label="学号" width="150" />
                <el-table-column prop="requestAuthInfo" label="认证身份" width="150" />
                <el-table-column prop="prove" label="证明图片" width="90">
                  <template #default="{ row }"
                    ><!--#default它用于接收具名插槽的默认内容，这里使用解构,可以在插槽内部访问这些变量并进行相关操作。。-->
                    <el-button
                      :icon="Picture"
                      circle
                      plain
                      type="primary"
                      @click="seeProve(row)"
                    ></el-button>
                  </template>
                </el-table-column>
                <el-table-column prop="action" label="操作" width="105">
                  <template #default="{ row }"
                    ><!--#default它用于接收具名插槽的默认内容，这里使用解构,可以在插槽内部访问这些变量并进行相关操作。。-->
                    <el-button
                      :icon="Check"
                      circle
                      plain
                      type="success"
                      @click="acceptApplication(row)"
                    ></el-button>
                    <el-button
                      :icon="Delete"
                      circle
                      plain
                      type="danger"
                      @click="refuseApplication(row)"
                    ></el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-col>

          <!-- 右边表格 -->
          <el-col :span="10" class="right">
            <div>
              <el-table
                :data="checkedData"
                style="width: 100%"
                :border="true"
                empty-text="暂时没有数据哦~"
                v-loading="loading"
                :height="tableHeight"
                @selection-change="handleSelectionChange1"
                stripe
                ref="multipleTable1"
              >
                <el-table-column type="index" label="索引" width="70" />
                <el-table-column prop="studentNum" label="学号" width="150" />
                <el-table-column prop="identity" label="认证身份" width="180" />
                <el-table-column prop="action" label="操作">
                  <template #default="{ row }"
                    ><!--#default它用于接收具名插槽的默认内容，这里使用解构,可以在插槽内部访问这些变量并进行相关操作。。-->
                    <el-button
                      :icon="Delete"
                      circle
                      plain
                      type="danger"
                      @click="refuseApplication(row)"
                    ></el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-col>
        </el-row>
      </div>
    </main>

    <!-- 图片区抽屉 -->
    <el-drawer v-model="pic" title="证明材料" direction="rtl" size="42%">
      <el-row :gutter="20">
        <template #default>
          <el-card
            v-for="(url, index) in srcList"
            :key="index"
            class="pic"
            style="width: 190px; height: 190px"
          >
            <el-image
              style="width: 150px; height: 150px"
              :src="url"
              fit="cover"
              :preview-src-list="[`${url}`]"
            />
          </el-card>
        </template>
        <!-- <el-col :span="6"><div class="grid-content"></div></el-col>
          <el-col :span="6"><div class="grid-content"></div></el-col>
          <el-col :span="6"><div class="grid-content"></div></el-col> -->
      </el-row>
    </el-drawer>
  </PageContainer>
</template>

<style lang="scss" scoped>
.header {
  //background-color: white;
  display: flex;
  // align-items: center;
  border-radius: 10px;
  // // background-color: #999;
  // width: 677px;
  // margin-left: -19px;
  justify-content: space-between;
  .header-left {
    background-color: #999;
    margin-left: -1.5%;
    width: 59.5%;
    border-radius: 15px;
    display: flex;
    text-align: center;
    align-items: center;
    justify-content: space-around;
    .btn {
      display: flex;
      justify-content: space-between;
      .true {
        margin-right: 10px;
      }
      .false {
        margin-left: 10px;
      }
    }
  }

  .header-right {
    background-color: #999;
    width: 42%;
    border-radius: 15px;
    display: flex;
    margin-right: -20px;
    justify-content: space-evenly;
    align-items: center;
  }
}
</style>
